package com.dongdongshop.controller;

import com.dongdongshop.data.Page;
import com.dongdongshop.data.Result;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.pojo.TbItemCat;
import com.dongdongshop.service.GoodsService;
import com.dongdongshop.service.ItemCatService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("goods")
public class GoodsController {

    @DubboReference
    private GoodsService goodsService;

    @DubboReference
    private ItemCatService itemCatService;

    @RequestMapping("toShow")
    public String toShow(){
        return "admin/goods";
    }

    @RequestMapping("goodsCat")
    @ResponseBody
    public Result goodsCat(){
        List<TbItemCat> list = itemCatService.getInfo();
        return Result.ok().setData(list);
    }

    @RequestMapping("getInfo")
    @ResponseBody
    public Result getInfo(TbGoods tbGoods,
                          @RequestParam(defaultValue = "1")Integer pageNum,
                          @RequestParam(defaultValue = "3")Integer pageSize){
        Page<TbGoods> page = goodsService.getInfo(tbGoods,pageNum,pageSize);
        return Result.ok().setData(page);
    }

    @RequestMapping("updateInfo")
    @ResponseBody
    public Result updateInfo(Long[] id,String auditStatus){
        goodsService.updateInfo(id,auditStatus);
        return Result.ok();
    }

    @RequestMapping("deleteInfo")
    @ResponseBody
    public Result deleteInfo(Long[] id){
        goodsService.deleteInfo(id);
        return Result.ok();
    }

}
